/*
 * Copyright (c) 2014 Hai Bison
 *
 * See the file LICENSE at the root directory of this project for copying
 * permission.
 */

package haibison.simpleprovider.simplesettings;

import static android.provider.BaseColumns._ID;
import static haibison.simpleprovider.SimpleContract._DATE_CREATED;
import static haibison.simpleprovider.SimpleContract._DATE_MODIFIED;
import static haibison.simpleprovider.SimpleProvider.UID;
import static haibison.simpleprovider.simplesettings.SimpleSettingsContract.COLUMN_KEY;
import static haibison.simpleprovider.simplesettings.SimpleSettingsContract.COLUMN_VALUE;
import static haibison.simpleprovider.simplesettings.SimpleSettingsContract.TABLE_NAME;
import haibison.simpleprovider.SimpleContract;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * SQLite helper class for Simple Settings provider.
 * 
 * @author Hai Bison
 *
 */
public class SimpleSettingsHelper extends SQLiteOpenHelper {

    /**
     * Database version.
     */
    public static final int DB_VERSION = 1;

    /**
     * Database filename.
     */
    public static final String DB_FILENAME = UID + ".simple-settings.sqlite";

    /**
     * SQL creator for table Simple Settings.
     */
    private static final String SQL_CREATOR_TABLE_SIMPLE_SETTINGS = "CREATE TABLE IF NOT EXISTS "
            + TABLE_NAME
            + " ( "
            + _ID
            + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "
            + _DATE_CREATED
            + " TEXT NOT NULL DEFAULT "
            + SimpleContract.formatNumber(0l, true)
            + ", "
            + _DATE_MODIFIED
            + " TEXT NOT NULL DEFAULT "
            + SimpleContract.formatNumber(0l, true)
            + ", "
            + COLUMN_KEY
            + " TEXT NOT NULL, " + COLUMN_VALUE + " TEXT)";

    /**
     * Creates new instance.
     * 
     * @param context
     *            the context.
     */
    public SimpleSettingsHelper(Context context) {
        super(context, DB_FILENAME, null, DB_VERSION);
    }// SimpleSettingsHelper()

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(SQL_CREATOR_TABLE_SIMPLE_SETTINGS);
    }// onCreate()

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        /*
         * Do nothing for now.
         */
    }// onUpgrade()

}
